package main

import (
	"log"
	_ "md52phone/boot"
	"md52phone/config"
	"md52phone/global"
	controller "md52phone/internal"
	"md52phone/pkg/rocksdb"

	"github.com/gin-gonic/gin"
)

func main() {
	var err error
	global.Service, err = rocksdb.NewRocksDBService(config.Conf.Rocks.NumShards, config.Conf.Rocks.DBPath)
	if err != nil {
		log.Fatal(err)
	}

	if config.Conf.Rocks.InitData {
		go controller.InitMd5Data()
	}

	r := gin.Default()
	gin.SetMode(config.Conf.App.RunMode)
	root := r.Group("../api")

	md5Ctl := controller.NewMd5Controller()

	root.GET("/md52phone", md5Ctl.Query)

	err = r.Run(":" + config.Conf.App.Port)
	if err != nil {
		log.Printf("HTTP服务启动异常：%v", err)
	}
}
